#pragma once
#include <cstdint>

const int SAFEIO_USRINPUT_MAX_CNT = 16;
const int SAFEIO_USROUTPUT_MAX_CNT = 16;

/**
 * @brief 用户安全输入事件
 * @note 必须要和proto文件中SafetyDIAction保持一致
 */
enum class SafeIO_UsrSafeInputEv : uint8_t
{
    RESRVER = 0,              // 不可配置
    NONE,                     // 无配置
    EXT_ESTOP,                // 附加急停
    EXT_SFSTOP,               // 附加保护性停止
    RESET_EXT_SFSTOP,         // 复位保护性停止
    REDUCED_MODE,             // 缩减模式，即降速到满足约束
    THREE_POSITION_ENABLING,  // 三位使能
    COLLISION_CLOSE,          // 即lv0，关闭碰撞监控
    COLLISION_LV1,            // lv值越高碰撞监控越不灵敏
    COLLISION_LV2,
    COLLISION_LV3,
    COLLISION_LV4,
    COLLISION_LV5,
    COLLISION_LV6
};

/**
 * @brief 用户安全输出事件
 * @note 必须要和proto文件中SafetyDOAction保持一致
 */
enum class SafeIO_UsrSafeOutputEv : uint8_t
{
    RESRVER = 0,      // 不可配置
    NONE,             // 无配置
    BP_ESTOP,         // 手柄急停
    SYS_ESTOP,        // 系统急停
    SYS_SFSTOP,       // 系统保护性停止
    MOVING,           // 机器人正在运动
    NOSTOP,           // 机器人未停止
    REDUCED,          // 机器人处于缩减模式
    NOREDUCED,        // 机器人未处于缩减模式
    COLLISION_CLOSE,  // 即lv0，关闭碰撞监控
    COLLISION_LV1,    // lv值越高碰撞监控越不灵敏
    COLLISION_LV2,
    COLLISION_LV3,
    COLLISION_LV4,
    COLLISION_LV5,
    COLLISION_LV6,
};

struct SafeIO_ConfigParam
{
    size_t usr_safein_ev_cnt = 0;
    SafeIO_UsrSafeInputEv usr_safein_ev[SAFEIO_USRINPUT_MAX_CNT] = {SafeIO_UsrSafeInputEv::RESRVER};
    size_t usr_safeout_ev_cnt = 0;
    SafeIO_UsrSafeOutputEv usr_safeout_ev[SAFEIO_USROUTPUT_MAX_CNT] = {SafeIO_UsrSafeOutputEv::RESRVER};

    struct UsrSafeInFuncChannel
    {
        int ext_stop = -1;
        int ext_sfstop = -1;
        int reset_ext_sfstop = -1;
        int reduced_mode = -1;
        int three_position_enabling = -1;
        int collision_close = -1;
        int collision_lv1 = -1;
        int collision_lv2 = -1;
        int collision_lv3 = -1;
        int collision_lv4 = -1;
        int collision_lv5 = -1;
        int collision_lv6 = -1;
    } usr_safein_func_channel;

    struct UsrSafeOutFuncChannel
    {
        int bp_estop = -1;
        int sys_estop = -1;
        int sys_sfstop = -1;
        int moving = -1;
        int nostop = -1;
        int reduced = -1;
        int noreduced = -1;
        int collision_close = -1;
        int collision_lv1 = -1;
        int collision_lv2 = -1;
        int collision_lv3 = -1;
        int collision_lv4 = -1;
        int collision_lv5 = -1;
        int collision_lv6 = -1;
    } usr_safeout_func_channel;

    bool three_position_enabling_drag_limit = false;  //三位使能拖动限制
    bool three_position_enabling_cat1stop = false;    //三位使能cat1停止，默认为cat2stop
    bool estop_manuel_reset = false;                  //急停手动复位,默认为自动复位
};